import FlowModelInstance from '@/components/flow/typs/FlowModelInstance.js';
import {openModal} from '@/utils/index.js';
import EdgeConfiguration from '@/components/flow/EdgeConfiguration/EdgeConfiguration.vue';

export default class EditEdgeCommand {
  supportInstance;
  edgeId;
  fieldComponentRegistry;

  constructor(supportInstance, edgeId, fieldComponentRegistry) {
    this.supportInstance = supportInstance;
    this.fieldComponentRegistry = fieldComponentRegistry;
    this.edgeId = edgeId;
  }

  serve() {
    let flowModelInstance = new FlowModelInstance(this.supportInstance.getModel());
    let edge = flowModelInstance.getEdgeById(this.edgeId);
    let fieldComponentRegistry = this.fieldComponentRegistry;
    if (!edge) return;
    openModal(EdgeConfiguration, {
      fieldComponentRegistry,
      fieldGroups: this.supportInstance.fieldGroups,
      edge, service: this.supportInstance.service, flowModelInstance, flowModel: this.supportInstance.getModel(),
    }, () => this.supportInstance.setModel(flowModelInstance.getModelString()));
  }
}